<?php 
include '../../public/common/mysql_connect.php';
include '../../public/common/init.php';

$sname=$_POST['name'];
$price=$_POST['price'];
$stock=$_POST['stock'];
$shelf=$_POST['shelf'];
$brand_id=$_POST['brand_id'];
// $sql="insert into shop(name,price,stock,isshelf,brand_id) values('{$sname}','{$price}','{$stock}','{$shelf}','{$brand_id}')";
// print_r($sql);exit;
// 	if(mysqli_query($conn,$sql)){
// 		echo '<script>location="index.php"</script>';
// 	}
// exit;
//图片上传
$src=$_FILES['img']['tmp_name'];

$name=$_FILES['img']['name'];

$arr=explode('.',$name);
// print_r($arr);exit;
$ext=array_pop($arr);

$dst=ROOT.createDir().time().mt_rand().'.'.$ext;
if(!($_FILES['img']['name']='') && $_FILES['img']['error']==0){
	if(move_uploaded_file($src,$dst)){
	//进行图片缩放200x200
	// makeThumb($dst,200,200);
	thumb($dst,200,200);
	$img=basename($dst);
	$sql="insert into shop(name,price,stock,isshelf,brand_id,img) values('{$sname}','{$price}','{$stock}','{$shelf}','{$brand_id}','{$img}')";
		if(mysqli_query($conn,$sql)){
			echo '<script>location="index.php"</script>';
		}
		else{
			echo '<script>alert("插入失败");</script>';
		}
	}
}



?>
